package com.jnshu.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import javax.annotation.Resource;

/**前端访问规则负载均衡拦截器*/
@Slf4j
@SpringBootConfiguration
public class WebMvcInterceptor extends WebMvcConfigurationSupport {

    @Resource
    WeChatInterceptor weChatInterceptor;

    /**
     * 拦截器按照顺序执行
     * addPathPatterns方法用于添加拦截规则
     * excludePathPatterns方法可排除拦截
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry){

        //拦截/u/下的所有请求
        registry.addInterceptor(weChatInterceptor)
                .addPathPatterns("/u/**")
                .excludePathPatterns("/u/login/code");
        log.info("微信前台拦截器调用通知");
        super.addInterceptors(registry);
    }
}
